/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rie06.openvoip.client.IHM.home;

import com.rie06.openvoip.client.Contact;
import com.rie06.openvoip.client.IHM.communication.CommunicationController;
import java.awt.Dimension;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.UUID;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import org.apache.log4j.Logger;

/**
 *
 * @author sylvain
 */
public class ListContactPanel extends JPanel {

    private InterfaceClient interfaceClient;
    private CommunicationController communicationController;
    private PanelContact panelContact;
    private static final Logger logger = Logger.getLogger(ListContactPanel.class);

    public ListContactPanel(InterfaceClient interfaceClient, CommunicationController communicationController) {

        this.interfaceClient = interfaceClient;
        this.communicationController = communicationController;

        this.setPreferredSize(new Dimension(190, 800));
        //updateListContact();
    }

    public void updateListContact() {

        this.removeAll();

        HashMap m = (HashMap) interfaceClient.getClient().getContactList();
        for (Iterator it = m.entrySet().iterator(); it.hasNext();) {
            Map.Entry<UUID, Contact> entry = (Map.Entry<UUID, Contact>) it.next();

            UUID uuid = entry.getKey();
            Contact contact = entry.getValue();

            panelContact = new PanelContact(this, contact, communicationController);

            this.add(panelContact);
        }

        this.add(new JLabel("                "));
        this.add(new JLabel("En attente d'ajout :"));
              
        HashMap m2 = (HashMap) interfaceClient.getClient().getContactListTemp();
        for (Iterator it = m2.entrySet().iterator(); it.hasNext();) {
            Map.Entry<UUID, Contact> entry = (Map.Entry<UUID, Contact>) it.next();

            UUID uuid = entry.getKey();
            Contact contact = entry.getValue();

            
            Icon iconWait = new ImageIcon(System.getProperty("user.home")+"/images/wait.gif"); 
            JLabel labelWait = new JLabel(iconWait);
            JLabel label = new JLabel(contact.getIpAddress().toString());

            //logger.log(Level.INFO, "Update ListContact : ");
            //logger.log(Level.DEBUG, "Description contact : " + contact.getName() + "IpAddress : " + contact.getIpAddress().toString());

            this.add(labelWait, LEFT_ALIGNMENT);
            this.add(label, LEFT_ALIGNMENT);

        }
        
        this.repaint();
        this.revalidate();

    }

    /**
     * ********* GETTEURS **************
     */
    public InterfaceClient getInterfaceClient() {
        return interfaceClient;
    }

    public PanelContact getPanelContact() {
        return panelContact;
    }
}
